package com.gdziarmaga.webshop.login.model;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import com.gdziarmaga.webshop.client.model.Client;
import com.gdziarmaga.webshop.transaction.model.Transaction;
//TODO creating validation 
//TODO setting precisions

@Entity
@Table(name = "Login")
public class Login implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public static final String LOGIN_DATE="login_date";
//	public static final String COMPUTER_IP="computer_ip";

	
	private Long login_id;
//	private String computer_ip;
	private Date login_date;
	
	private Client client;
	private List<Transaction> transaction_list;

	
	@ManyToOne(cascade = CascadeType.PERSIST)
    @JoinColumn(name = "client_id", nullable=false, updatable=false)
	public Client getClient(){
		return client;
	}
	
	public void setClient(Client client){
		this.client=client;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "login_seq")
	@SequenceGenerator(name = "login_seq", sequenceName = "LOGIN_SEQ")
	@Column(name = "login_id", precision = 20, scale = 0, unique=true)
	public Long getLogin_id() {
		return login_id;
	}

	public void setLogin_id(Long login_id) {
		this.login_id = login_id;
	}

	@Column(name="login_date", nullable=false, length=20)
	public Date getLogin_date() {
		return login_date;
	}

	public void setLogin_date(Date login_date) {
		this.login_date = login_date;
	}

	public void setTransaction_list(List<Transaction> transaction_list) {
		this.transaction_list = transaction_list;
	}

	@OneToMany(mappedBy = "login", cascade = CascadeType.PERSIST)
	@JoinColumn(name = "login_id")
	public List<Transaction> getTransaction_list() {
		return transaction_list;
	}

}
